package cn.xuqiudong.console.config;

import cn.xuqiudong.common.base.aspect.RepeatCommitVersionAspect;
import cn.xuqiudong.common.base.aspect.RequestLogPrintAspect;
import cn.xuqiudong.common.base.tool.ApplicationContextHolder;
import cn.xuqiudong.common.base.web.GlobalExceptionHandler;
import org.slf4j.Logger;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 描述:
 *  一些通用的配置
 * @author Vic.xu
 * @since 2024-06-19 16:33
 */
@Configuration
public class CommonConfig {

    private static final Logger LOGGER = org.slf4j.LoggerFactory.getLogger(CommonConfig.class);

    @Bean
    @ConditionalOnMissingBean
    public ApplicationContextHolder applicationContextHolder(){
        return new ApplicationContextHolder();
    }

    @Bean
    @ConditionalOnMissingBean
    public GlobalExceptionHandler globalExceptionHandler(){
        LOGGER.info("init GlobalExceptionHandler");
        return new GlobalExceptionHandler();
    }


    @Bean
    @ConditionalOnMissingBean
    public RequestLogPrintAspect requestLogPrintAspect(){
        return new RequestLogPrintAspect();
    }

    @Bean
    @ConditionalOnMissingBean
    public RepeatCommitVersionAspect repeatCommitVersionAspect(){
        return new RepeatCommitVersionAspect();
    }
}
